<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
echo "<h2>Голосования</h2>";
$this->table->set_heading('id', 'Название', 'Изображение', 'Результаты', 'Действия');
$tmpl = array('table_open' => '<table border="0" cellpadding="0" cellspacing="0" class="admin_table">');
$this->table->set_template($tmpl);

$class = 'polls';
if ($this->users_rights_model->check_rights($class, 'block', true)) $canblock = 1;
if ($this->users_rights_model->check_rights($class, 'unblock', true)) $canblock = 1;
if ($this->users_rights_model->check_rights($class, 'edit', true)) $canedit = 1;
if ($this->users_rights_model->check_rights($class, 'delete', true)) $candelete = 1;
if ($this->users_rights_model->check_rights($class, 'add', true)) $canadd = 1;


foreach ($pages as $page) {
	$answers = $this->db->select()->from('answers')->where('answer_poll', $page['poll_id'])->get()->result_array();
	$text = "";
	$one_procent = $page['poll_count'] / 100;
	foreach ($answers as $answer) {
		if ($one_procent > 0)
			$this_procent = $answer['answer_count'] / $one_procent;
		else
			$this_procent = 0;
		$text .= $answer['answer_text']." - ".$answer['answer_count']." голосов, ".$this_procent."%<br />";
	}
	$this->table->add_row(
			$page['poll_id'],
			"<a href='/admin/polls/edit/".$page['poll_id']."/'>".$page['poll_title']."</a>",
			($page['poll_image'] != ""?"<img src='/uploads/polls/".$page['poll_id']."/small/".$page['poll_image']."'>":""),
			$text,
			showmeactions(
					$class,
					$page['poll_id'],
					$page['poll_status'],
					0, $candelete, 0,
					$from
				)
		);
}
echo $this->table->generate();
echo $paging;
echo $form;
echo "<div class='cc'></div>";
?>
